package com.gitee.wsl.coroutines.collections.sequences

import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.experimental.ExperimentalTypeInference

interface SuspendingSequenceScope<in T> {
    suspend fun yield(value: T)
}

interface SuspendingSequence<out T> {
    operator fun iterator(): SuspendingIterator<T>
}


@OptIn(ExperimentalTypeInference::class)
fun <T> suspendingSequence(
    context: CoroutineContext = EmptyCoroutineContext,
    @BuilderInference block: suspend SuspendingSequenceScope<T>.() -> Unit
): SuspendingSequence<T> = object : SuspendingSequence<T> {
    override fun iterator(): SuspendingIterator<T> = suspendingIterator(context, block)
}

